package com.example.demo.dao;

import com.example.demo.model.Articleinfo;
import com.example.demo.model.Articleinfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:  映射层articleMapper
 * User: yyx
 * Date: 2023-11-05
 * Time: 14:34
 */
public interface ArticleMapper {
    @Select("select * from articleinfo where uid = #{uid} order by id desc")
    List<Articleinfo> getArtByUid(@Param("uid")int uid);

    @Delete("delete from articleinfo where id = #{aid} and uid = #{uid}")
    int del(@Param("aid")Integer aid,@Param("uid")int uid);

    @Insert("insert into articleinfo(title,content,uid) values(#{title},#{content},#{uid})" )
    int add(Articleinfo articleinfo);

    @Select("select * from articleinfo where id=#{aid} and uid=#{uid}")
    Articleinfo getArtByidAnduid(@Param("aid")int aid,@Param("uid")int uid);

    @Update("update articleinfo set title = #{title},content = #{content} where uid = #{uid} and id = #{id}")
    int update(Articleinfo articleinfo);

    @Select("select * from articleinfo where id=#{aid}")
    Articleinfo getDetailByid(@Param("aid")int aid);

    @Select("select count(*) from articleinfo where uid = #{uid}")
    int getArtCountByUid(@Param("uid")int uid);

    @Update("update articleinfo set rcount = rcount+1 where id = #{aid}")
    int increment(@Param("aid")int aid);

    @Select("select * from articleinfo order by id desc limit #{psize} offset #{offset}")
    List<Articleinfo> getListByPage(@Param("psize")int psize,@Param("offset")int offset);

    @Select("select count(*) from articleinfo")
    int getArtCount();

}
